<?php

declare(strict_types=1);

namespace app\admin\validate;

use think\Validate;

class Dictionary extends Validate
{
     /**
     * 定义验证规则
     * 格式：'字段名' =>  ['规则1','规则2'...].
     *
     * @var array
     */
    protected $rule = [
        'dictionary_id' => 'require|number|gt:0',
        'parent_id' => 'require|number|egt:0',
        'name_zh' => 'require|chs|min:2|unique:dictionary',
        'name_en' => 'require|alphaDash|min:2|unique:dictionary',
        'sort' => 'require|number|gt:0',
        'page' => 'require|number|gt:0',
        'limit' => 'require|number|gt:5',
    ];
    protected $scene = [
        'getDictionaryListPage' => ['page', 'limit'],
        'saveDictionaryAdd' => ['parent_id', 'name', 'name_en', 'sort'],
        'getDictionaryRow' => ['dictionary_id'],
        'saveDictionaryEdit' => ['dictionary_id'],
        'saveDictionaryDel' => ['dictionary_id'],
        'getTagDictionary' => ['name_en'],
    ];
    protected function sceneGetTagDictionary()
    {
        return $this->only(['name_en'])
            ->remove('name_en', 'unique');
    }
}